package com.glsc.ngateway.platform.service.itflow.flowstrategy.systemNameApply.taskPostHandler;

import com.glsc.ngateway.common.api.common.enums.RabbitExcQueConstant;
import com.glsc.ngateway.common.api.flowable.dto.task.doTaskParam.system.SystemPassParamDto;
import com.glsc.ngateway.common.api.flowable.dto.task.doTaskParam.system.SystemRejectParamDto;
import com.glsc.ngateway.common.api.flowable.dto.task.formData.system.SystemNameApplyTaskFormDataDto;
import com.glsc.ngateway.common.api.flowable.dto.task.formData.system.domainDto.FlowFormSystemNameApplyDto;
import com.glsc.ngateway.common.api.flowable.dto.task.message.SystemFlowMessageDto;
import com.glsc.ngateway.common.api.flowable.resp.ResponseSituationDto;
import com.glsc.ngateway.common.base.domain.mysql.gateway.platform.flow.FlowFormSystemNameApply;
import com.glsc.ngateway.common.base.enums.itflow.ITFlowTaskEnum;
import com.glsc.ngateway.common.base.repo.mysql.gateway.platform.FlowFormSystemNameApplyRepo;
import com.glsc.ngateway.platform.service.FlowCommonService;
import com.glsc.ngateway.platform.utils.MqUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.validation.constraints.NotNull;

/**
 * 一级部门负责人审批
 * @author xuchang
 */
@Component
public class SNAStep3DepartmentSuperTaskPostHandlerAudit implements ISystemNameApplyTaskPostHandlerAudit {

    private final Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private SNAStepHandlerHelper handlerHelper;

    @Autowired
    private FlowCommonService flowCommonService;

    @Autowired
    private FlowFormSystemNameApplyRepo systemNameApplyRepo;
    /**
     * 审批通过后置处理
     */
    @Override
    public void passAfterHandle(@NotNull SystemPassParamDto<FlowFormSystemNameApplyDto, SystemNameApplyTaskFormDataDto> param, String operator) {
        handlerHelper.endTaskAfterHandle(param, operator);
        //如果当前节点走完，发送MQ，添加系统数据
        SystemFlowMessageDto message = new SystemFlowMessageDto();
        FlowFormSystemNameApply apply = systemNameApplyRepo.findByProcessId(param.getProcessId());
        message.setMainFormId(apply.getId());
        message.setDefineKey(ITFlowTaskEnum.SYSTEM_NAME_APPLY_FLOW_LEADER_TASK.getMqCodeKey());
        message.setOperator(operator);
        MqUtil.sendMessage(RabbitExcQueConstant.AMPRODUCT_EXCHANGE_DEFAULT, RabbitExcQueConstant.AMPRODUCT_QUEUE_GATEWAY_FLOW_REMIND, message);
    }

    @Override
    public String getTaskDefinitionKey() {
        return ITFlowTaskEnum.SYSTEM_NAME_APPLY_FLOW_DEPARTMENT_SUPER_TASK.getTaskKey();
    }

    /**
     * 驳回后置处理方法
     */
    @Override
    public void rejectAfterHandle(@NotNull SystemRejectParamDto param, @NotNull String operator) {
        handlerHelper.afterHandle(param, operator);
    }

}
